package com.zjitc.controller;

import com.zjitc.model.User;
import com.zjitc.service.CartService;
import com.zjitc.service.CatService;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/16 16:02
 * @description:
 */
@Controller
@RequestMapping("/cart")
public class CartController {

  @Autowired
  private CartService cartService;

  @RequestMapping(value = "/remove")
  public String remove(@RequestParam("id") int id, HttpSession session) {
    User user = (User) session.getAttribute("user");
    if (user == null) {
      String msg = "请登录再进行操作";
      ModelAndView modelAndView = new ModelAndView();
      modelAndView.addObject("msg", msg);
      return "user/form-2/login";
    }
    try {
      cartService.removeUsernameAndSell(id);
      return "user/cartLIst.do?username="+user.getUsername();
    }catch (Exception e){
      String msg = "您的购物车中没有商品，请选择商品后再来";
      return "user/form-2/msg02";
    }


    /*return "redirect:checkout.do?username="+user.getUsername();*/
  }
/*  @RequestMapping(value = "/checkout")
  public String checkout(@RequestParam("username") String username){
    cartService.
  }*/
@RequestMapping(value = "/orderList")
  public String orderList(String username){
  List list = cartService.orderList(username);
  ModelAndView modelAndView = new ModelAndView();
  modelAndView.addObject("orderlist",list);
  return "cart/orderlist";
}
}
